import { Ability, AbilityConstant } from '@ohos.app.ability';
import common from '@ohos.app.ability.common';
import { AudioController } from '../model/AudioController';

export default class EntryAbility extends Ability {
  onCreate(want: common.Want, launchParam: AbilityConstant.LaunchParam): void {
    console.info('EntryAbility onCreate');
    // 初始化音频控制器
    AudioController.getInstance(this.context);
  }

  onDestroy(): void {
    console.info('EntryAbility onDestroy');
    // 释放音频资源
    AudioController.getInstance().release();
  }

  onWindowStageCreate(windowStage: common.WindowStage): void {
    console.info('EntryAbility onWindowStageCreate');
    // 设置窗口
    windowStage.loadContent('pages/MainIndex', (err, data) => {
      if (err) {
        console.error('Failed to load content:', err);
      } else {
        console.info('Succeeded to load content:', data);
      }
    });
  }

  onWindowStageDestroy(): void {
    console.info('EntryAbility onWindowStageDestroy');
    // 取消窗口监听
  }

  onForeground(): void {
    console.info('EntryAbility onForeground');
  }

  onBackground(): void {
    console.info('EntryAbility onBackground');
  }
}